package com.example.travel_front.Fragment;

import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.travel_front.Adapter.HourlyForecastAdapter;
import com.example.travel_front.Adapter.RoutesAdapter;
import com.example.travel_front.Model.DayDetail;
import com.example.travel_front.Model.HourlyForecast;
import com.example.travel_front.Model.Route;
import com.example.travel_front.R;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.tabs.TabLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class SearchResultFragment extends Fragment {


    private LinearLayout bgContainer;
    private AppBarLayout appBarLayout;
    private RecyclerView routesRecyclerView;
    private TabLayout dayTabLayout;
    AppCompatButton routeFirstBtn;
    AppCompatButton routeSecondBtn;
    AppCompatButton routeThirdBtn;
    private LinearLayout infoPreviewLayout;
    private TextView dayNumberText;
    private TextView locationNumberText;
    private RecyclerView dayDetailRecyclerView;
    private LinearLayout dayDetailContainer;
    private NestedScrollView scrollView;
    private MaterialToolbar titleToolbar;

    RoutesAdapter routesAdapter;
    List<Route> currentRouteList = new ArrayList<>();
    List<List<Route>> testList = new ArrayList<>();

    // 存储标题位置
    List<TextView> headViewList = new ArrayList<>();
    List<Integer> headHeightList = new ArrayList<>();

    // 背景图
    String bgUrl = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_search_result, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initViews(view);
        // 初始化测试数据
        generateFakeRouteList();
        List<HourlyForecast> forecastList = getHourlyForecasts(); // This should return List<HourlyForecast>

        RecyclerView recyclerView = view.findViewById(R.id.hourlyForecastRecyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        HourlyForecastAdapter adapter = new HourlyForecastAdapter(forecastList);
        recyclerView.setAdapter(adapter);
        // 背景图
        Glide.with(requireContext())
                .load(bgUrl)
                .into(new CustomTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        bgContainer.setBackground(resource);
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                    }
                });
        initTabLayout();
        dayNumberText.setText(String.valueOf(currentRouteList.size()));
        int dayDetailCount = currentRouteList.stream().mapToInt(route -> route.dayDetailList.size()).sum();
        locationNumberText.setText(String.valueOf(dayDetailCount));
        // 初始化路线列表
        routesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
        routesAdapter = new RoutesAdapter(currentRouteList);
        routesRecyclerView.setAdapter(routesAdapter);
        routesAdapter.setOnItemClickListener((route, position) -> {
            dayTabLayout.selectTab(dayTabLayout.getTabAt(position));
            appBarLayout.setExpanded(false);
        });

        initDayDetailData();

        initListeners();

        getView().getViewTreeObserver().addOnWindowFocusChangeListener(hasFocus -> {
            for (TextView headView : headViewList) {
                headHeightList.add(headView.getTop() - 50);
            }
        });
    }

    private void initViews(View view) {
        // 初始化
        bgContainer = view.findViewById(R.id.bgContainer);
        appBarLayout = view.findViewById(R.id.appBarLayout);
        routesRecyclerView = view.findViewById(R.id.routesRecyclerView);
        dayTabLayout = view.findViewById(R.id.dayTabLayout);
        routeFirstBtn = view.findViewById(R.id.routeFirstBtn);
        routeSecondBtn = view.findViewById(R.id.routeSecondBtn);
        infoPreviewLayout = view.findViewById(R.id.journeyInfoLayout);
        routeThirdBtn = view.findViewById(R.id.routeThirdBtn);
        dayNumberText = view.findViewById(R.id.dayNumber);
        locationNumberText = view.findViewById(R.id.locationNumber);
        dayDetailContainer = view.findViewById(R.id.dayDetailContainer);
        scrollView = view.findViewById(R.id.scrollView);
        titleToolbar = view.findViewById(R.id.titleToolbar);
    }


    /**
     * 动态生成 Tab（第几天）
     */
    private void initTabLayout() {
        dayTabLayout.removeAllTabs();
        for (int i = 0; i < currentRouteList.size(); i++) {
            TabLayout.Tab newTab = dayTabLayout.newTab();
            newTab.setText(getResources().getString(R.string.day_of_month, CN_NUM[i]));
            dayTabLayout.addTab(newTab);
        }
    }

    /**
     * 切换路线
     */
    private void reloadData() {
        initTabLayout();
        routesAdapter.loadData(currentRouteList);
        initDayDetailData();
    }

    /**
     * 每天路线的列表
     */
    private void initDayDetailData() {
        dayDetailContainer.removeAllViews();
        headViewList.clear();
        for (Route route : currentRouteList) {
            TextView headView = new TextView(requireContext());
            headView.setTextSize(16);
            headView.setTextColor(getResources().getColor(R.color.black));
            headView.setTypeface(headView.getTypeface(), Typeface.BOLD);
            List<DayDetail> dayDetailList = route.dayDetailList;
            String info = "";
            if (dayDetailList.size() >= 1) {
                info = "・" + dayDetailList.get(0).location;
            }
            if (dayDetailList.size() > 1) {
                info += "-" + dayDetailList.get(dayDetailList.size() - 1).location;
            }
            headView.setText(
                    getResources().getString(R.string.day_of_month, CN_NUM[currentRouteList.indexOf(route)]) + info
            );
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(32, 60, 0, 32);
            headView.setLayoutParams(params);
            dayDetailContainer.addView(headView);
            headViewList.add(headView);
            for (DayDetail dayDetail : route.dayDetailList) {
                View itemView = LayoutInflater.from(requireContext()).inflate(R.layout.item_day_detail, null, false);
                ImageView thumbView = itemView.findViewById(R.id.thumb);
                TextView location = itemView.findViewById(R.id.location);
                TextView description = itemView.findViewById(R.id.description);
                TextView address = itemView.findViewById(R.id.address);
                TextView rating = itemView.findViewById(R.id.rating);
                Glide
                        .with(this)
                        .load(dayDetail.image_url)
                        .centerCrop()
                        .override(100, 100)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                        .into(thumbView);
                location.setText(dayDetail.location);
                description.setText(dayDetail.description);
                description.setSelected(true);
                address.setText(dayDetail.address);
                address.setSelected(true);
                rating.setText(dayDetail.rating);
                dayDetailContainer.addView(itemView);
            }
        }
    }

    private void initListeners() {
        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.BaseOnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                // 折叠
                if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                    dayTabLayout.setVisibility(View.VISIBLE);
                    infoPreviewLayout.setVisibility(View.GONE);
                } else {
                    dayTabLayout.setVisibility(View.GONE);
                    infoPreviewLayout.setVisibility(View.VISIBLE);
                }
            }
        });

        dayTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                scrollView.smoothScrollTo(0, headHeightList.get(dayTabLayout.getSelectedTabPosition()));
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
//        routeFirstBtn.setOnClickListener(view -> {
//            currentRouteList = testList.get(0);
//            reloadData();
//        });
//        routeSecondBtn.setOnClickListener(view -> {
//            currentRouteList = testList.get(1);
//            reloadData();
//        });
//        routeThirdBtn.setOnClickListener(view -> {
//            currentRouteList = testList.get(2);
//            reloadData();
//        });

        titleToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                requireActivity().onBackPressed();
            }
        });
    }

    private String fakeJson() {
        return "{\n" +
                "\t\"bg_url\": \"https://cdn.pixabay.com/photo/2011/06/21/14/50/iceland-poppy-8110_1280.jpg\",\n" +
                "\t\"day1\": {\n" +
                "\t\t\"08:00-12:00\": {\n" +
                "\t\t\t\"行程地点\": \"秦岭山脉\",\n" +
                "\t\t\t\"行程描述\": \"欣赏秦岭山脉的自然风光，进行森林爬山\",\n" +
                "\t\t\t\"latitude\": \"33.764871\",\n" +
                "\t\t\t\"longitude\": \"108.298604\",\n" +
                "\t\t\t\"type\": \"地名地址信息;自然地名;山\",\n" +
                "\t\t\t\"address\": \"周至县\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": [],\n" +
                "\t\t\t\"image_url\": []\n" +
                "\t\t},\n" +
                "\t\t\"12:00-13:30\": {\n" +
                "\t\t\t\"行程地点\": \"秦岭山脚下的小吃街\",\n" +
                "\t\t\t\"行程描述\": \"品尝地道的西安特色小吃\",\n" +
                "\t\t\t\"latitude\": \"33.851440\",\n" +
                "\t\t\t\"longitude\": \"108.783509\",\n" +
                "\t\t\t\"type\": \"地名地址信息;自然地名;山\",\n" +
                "\t\t\t\"address\": \"长安区\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": [],\n" +
                "\t\t\t\"image_url\": []\n" +
                "\t\t},\n" +
                "\t\t\"14:00-16:00\": {\n" +
                "\t\t\t\"行程地点\": \"大雁塔\",\n" +
                "\t\t\t\"行程描述\": \"参观大雁塔，了解西安的历史文化\",\n" +
                "\t\t\t\"latitude\": \"34.218285\",\n" +
                "\t\t\t\"longitude\": \"108.964162\",\n" +
                "\t\t\t\"type\": \"风景名胜;风景名胜;风景名胜\",\n" +
                "\t\t\t\"address\": \"雁塔南路附近\",\n" +
                "\t\t\t\"average_cost\": \"30.00\",\n" +
                "\t\t\t\"rating\": \"4.9\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/00f713e61c99c4956ab27df73afdde71\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/cd3e0cff14bb6aeb3d2b02936dff15ad\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/63a9a15aab2376a24fb3179326d28a55\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"16:00-17:30\": {\n" +
                "\t\t\t\"行程地点\": \"回民街\",\n" +
                "\t\t\t\"行程描述\": \"在回民街品尝美食，感受西安的独特魅力\",\n" +
                "\t\t\t\"latitude\": \"34.262260\",\n" +
                "\t\t\t\"longitude\": \"108.943607\",\n" +
                "\t\t\t\"type\": \"购物服务;特色商业街;步行街\",\n" +
                "\t\t\t\"address\": \"北院门125号1-51(钟楼地铁站出入口步行430米)\",\n" +
                "\t\t\t\"average_cost\": \"15.00\",\n" +
                "\t\t\t\"rating\": \"4.8\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/ed23f16e879b95e643fde2fcc935bed4\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/afbf459b0e84f21e61ed6b98d7a5671b\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/d26415f3cec64b43dec8326299534486\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"18:00-20:00\": {\n" +
                "\t\t\t\"行程地点\": \"西安美仑酒店\",\n" +
                "\t\t\t\"行程描述\": \"入住酒店，休息放松\",\n" +
                "\t\t\t\"latitude\": \"34.259805\",\n" +
                "\t\t\t\"longitude\": \"108.967565\",\n" +
                "\t\t\t\"type\": \"住宿服务;宾馆酒店;三星级宾馆\",\n" +
                "\t\t\t\"address\": \"东大街69号东大街尚勤路口solo公寓4层(近解放路)\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": \"3.9\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"Logo\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/2c0003ea0fa46b67722a5189325103bf\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"主图\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/3ce55b2ab7942449168ad3a7bb091e45\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/dfcf57b8d40ec5afcae4d7a1b960dee8\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t}\n" +
                "\t},\n" +
                "\t\"day2\": {\n" +
                "\t\t\"08:00-10:00\": {\n" +
                "\t\t\t\"行程地点\": \"西安城墙\",\n" +
                "\t\t\t\"行程描述\": \"骑行或步行在西安城墙上，俯瞰城市风光\",\n" +
                "\t\t\t\"latitude\": \"34.275848\",\n" +
                "\t\t\t\"longitude\": \"108.947207\",\n" +
                "\t\t\t\"type\": \"风景名胜;风景名胜;国家级景点\",\n" +
                "\t\t\t\"address\": \"南大街2号\",\n" +
                "\t\t\t\"average_cost\": \"54.00\",\n" +
                "\t\t\t\"rating\": \"4.9\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/f858d7753932ea21d02a7990a5bec413\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"西安城墙\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/696c6e0108cf677ea995fcda9d2cc79e\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"西安城墙\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/2e1e31967ad8581b8721203e322980cf\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"10:00-12:00\": {\n" +
                "\t\t\t\"行程地点\": \"森林公园\",\n" +
                "\t\t\t\"行程描述\": \"在森林公园进行森林爬山，享受大自然的宁静与美丽\",\n" +
                "\t\t\t\"latitude\": \"34.174858\",\n" +
                "\t\t\t\"longitude\": \"108.931821\",\n" +
                "\t\t\t\"type\": \"风景名胜;公园广场;公园\",\n" +
                "\t\t\t\"address\": \"西部大道与东仪路交叉口东500米路北\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": \"4.7\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/8c44ffbe9361ddf35c5ae5031fb930cc\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"清凉山国家森林公园\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/f3cd269a36af297bb91b1c1a266c412e\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"清凉山国家森林公园\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/7211a2e919d324187bdb7b23e65affa8\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"12:00-13:30\": {\n" +
                "\t\t\t\"行程地点\": \"城墙附近的永兴坊\",\n" +
                "\t\t\t\"行程描述\": \"品尝永兴坊的特色美食，体验西安的饮食文化\",\n" +
                "\t\t\t\"latitude\": \"34.264900\",\n" +
                "\t\t\t\"longitude\": \"108.970162\",\n" +
                "\t\t\t\"type\": \"风景名胜;风景名胜;风景名胜\",\n" +
                "\t\t\t\"address\": \"东新街与顺城东路北段交叉口西北100米\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": \"4.8\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/d3dd18fa5fb617d02cf7f1aabae80b78\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/85ea50d0789107b270db6dbba146d25a\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/f98c362dd4f0203080c10af3b029fb4c\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"14:00-16:00\": {\n" +
                "\t\t\t\"行程地点\": \"开元商城\",\n" +
                "\t\t\t\"行程描述\": \"在开元商城购物休闲，体验西安的商业氛围\",\n" +
                "\t\t\t\"latitude\": \"34.258584\",\n" +
                "\t\t\t\"longitude\": \"108.948139\",\n" +
                "\t\t\t\"type\": \"购物服务;商场;普通商场\",\n" +
                "\t\t\t\"address\": \"东大街解放市场6号\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": \"4.7\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/84ea4b4d549f241241d8e5b8c641599d\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"title\": [],\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/b5c155c6b596546736ea96299bae9ecf\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"title\": \"外景图\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/e024e06227253cd1e6ddfaf2bce21370\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t},\n" +
                "\t\t\"18:00-20:00\": {\n" +
                "\t\t\t\"行程地点\": \"万豪酒店\",\n" +
                "\t\t\t\"行程描述\": \"入住酒店，享受舒适的住宿环境\",\n" +
                "\t\t\t\"latitude\": \"34.233015\",\n" +
                "\t\t\t\"longitude\": \"108.894605\",\n" +
                "\t\t\t\"type\": \"住宿服务;宾馆酒店;五星级宾馆\",\n" +
                "\t\t\t\"address\": \"高新四路16号\",\n" +
                "\t\t\t\"average_cost\": [],\n" +
                "\t\t\t\"rating\": \"4.7\",\n" +
                "\t\t\t\"image_url\": [{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"Logo\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/ab6d959ba3f8bd95fb86be652d9071d2\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"主图\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/f7d5e1bdfe42d598e64406f059214a44\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\t\"provider\": [],\n" +
                "\t\t\t\t\t\"title\": \"公共区域\",\n" +
                "\t\t\t\t\t\"url\": \"http://store.is.autonavi.com/showpic/82a24f2a3cd9e95da4d27a3176cf25c5\"\n" +
                "\t\t\t\t}\n" +
                "\t\t\t]\n" +
                "\t\t}\n" +
                "\t}\n" +
                "}";
    }

    private List<HourlyForecast> getHourlyForecasts() {
        List<HourlyForecast> forecastList = new ArrayList<>();

        // Adding some sample data
        forecastList.add(new HourlyForecast("6 AM", R.drawable.ic_fine, "20°C"));
        forecastList.add(new HourlyForecast("7 AM", R.drawable.ic_cloudy, "21°C"));
        forecastList.add(new HourlyForecast("8 AM", R.drawable.ic_cloudy, "22°C"));
        forecastList.add(new HourlyForecast("9 AM", R.drawable.ic_cloudy, "18°C"));
        forecastList.add(new HourlyForecast("10 AM", R.drawable.ic_blizzard, "17°C"));
        forecastList.add(new HourlyForecast("11 AM", R.drawable.ic_cloudy, "18°C"));
        forecastList.add(new HourlyForecast("12 AM", R.drawable.ic_blizzard, "17°C"));

        return forecastList;
    }

    public void generateFakeRouteList() {
        List<Route> routeList = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(fakeJson());
            // 天数
            JSONArray names = jsonObject.names();
            for (int i = 0; i < names.length(); i++) {
                if (names.getString(i).equals("bg_url")) {
                    bgUrl = jsonObject.getString("bg_url");
                    continue;
                }
                Route route = new Route();
                String day = names.getString(i);
                route.day = getResources().getString(R.string.day_of_month, CN_NUM[i]);
                // 每日信息
                JSONArray times = jsonObject.getJSONObject(day).names();
                List<DayDetail> dayDetailList = new ArrayList<>();
                for (int j = 0; j < times.length(); j++) {
                    String time = times.getString(j);
                    JSONObject dayDetailObject = jsonObject.getJSONObject(day).getJSONObject(time);
                    String image_url = "";
                    if (dayDetailObject.getJSONArray("image_url").length() != 0) {
                        image_url = dayDetailObject.getJSONArray("image_url").getJSONObject(0).getString("url");
                    }
                    DayDetail dayDetail = new DayDetail(
                            time,
                            dayDetailObject.getString("行程地点"),
                            dayDetailObject.getString("行程描述"),
                            dayDetailObject.getString("latitude"),
                            dayDetailObject.getString("longitude"),
                            dayDetailObject.getString("type"),
                            dayDetailObject.getString("address"),
                            dayDetailObject.getString("average_cost"),
                            dayDetailObject.getString("rating"),
                            image_url
                    );
                    dayDetailList.add(dayDetail);
                }
                route.dayDetailList = dayDetailList;
                routeList.add(route);
            }
            currentRouteList = routeList;
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private static final String[] CN_NUM = {"一", "二", "三", "四", "五", "六", "七", "八", "九"};
    private static String[] testCity = {"北京", "苏州", "上海", "广州"};
}
